#ifndef SD_DATAWRITERLISTENER_HH_
#define SD_DATAWRITERLISTENER_HH_

#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>

using namespace eprosima::fastdds::dds;

class SDPltDataWriterListener:public DataWriterListener{
public:
    std::atomic_int matched_;
    SDPltDataWriterListener(){
        this->matched_=0;
    }
    ~SDPltDataWriterListener() override{

    }
    void on_publication_matched(DataWriter* writer, const PublicationMatchedStatus& info) override{
        if(info.current_count_change==1){
            this->matched_=info.total_count;
            std::cout<<"Publisher matched. c:"<<this->matched_<<std::endl;
        }else if(info.current_count_change==-1){
            this->matched_=info.total_count;
            std::cout<<"Publisher unmatched. c:"<<this->matched_<<std::endl;
        }else{
            std::cout<<"Publisher matching error!"<<std::endl;
        }

    }
};

#endif